package com.test.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * 设备类型
 *
 * @author sangkuofeng
 * @date 2023/11/12 01:22
 */
public enum DeviceType {

    IC_CARD("iccard", "IC读卡器"),
    ID_CARD("idcard", "身份证读卡器"),
    MULTIPLE_TYPE_CARD("multipletypecard", "二合一读卡器（IC+身份证）"),
    WEIGHBRIDGE("weighbridge", "地磅"),
    CAMERA_CPSB("cameraCPSB", "车牌识别摄像一体机"),
    CAMERA_HD("cameraHD", "高清摄像机"),
    USB_CAMERA("usbcamera", "USB摄像头"),
    ALTIMETER("altimeter", "高拍仪"),
    ;

    private String code;
    private String name;

    DeviceType(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static DeviceType getTypeByCode(String code) {
        Optional<DeviceType> optional = Arrays.stream(DeviceType.values()).filter(item -> StringUtils.equals(code, item.getCode())).findFirst();
        return optional.isPresent() ? optional.get() : null;
    }

}
